package org.example.blog.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;


@Configuration
@EnableAsync
public class AsyncConfiguration {

    @Bean
    public Executor asyncExecutor(){
//        配置线程池
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
//        分配核心数
        executor.setCorePoolSize(2);
//        最大线程数
        executor.setMaxPoolSize(10);
//        线程名称
        executor.setThreadNamePrefix("sob_blog_task_worker-");
//        队列容量
        executor.setQueueCapacity(30);
//        初始化
        executor.initialize();
        return executor;
    }
}
